package com.zingrow.web.customer.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zingrow.common.utils.PageView;
import com.zingrow.web.base.service.impl.BaseService;
import com.zingrow.web.customer.mapper.GroupSchemeMapper;
import com.zingrow.web.customer.model.GroupScheme;
import com.zingrow.web.customer.service.IGroupSchemeService;

@Service
public class GroupSchemeService extends BaseService<GroupScheme> implements IGroupSchemeService {

	@Autowired
	private GroupSchemeMapper groupSchemeMapper;

	@Override
	public void initMapper() {
		this.baseMapper= groupSchemeMapper;	
	}
	
	/*@Override
	public boolean insert(List<Integer> list, Integer groupId,Integer ifmIsSensitivity) {
		// 删除
		boolean flag = delGroupScheme(groupId);

		String[] schemeId = list.toArray(new String[list.size()]);

		Map<String, Object> map = new HashMap<String, Object>();

		if (schemeId != null && schemeId.length != 0 ) {
			map.put("schemeId", schemeId);
			map.put("groupId", groupId);
			map.put("ifmIsSensitivity", ifmIsSensitivity);
			if (flag) {
				return groupSchemeMapper.insert(map) > 0;
			}
		} else {
			return true;
		}
		return false;
	}*/
	/**
	 * 新增组织方案接口——政府版
	 * @param groupScheme
	 * @return
	 */
	/*@Override
	public boolean insertGroup(GroupScheme groupScheme){
		return groupSchemeMapper.insertGroup(groupScheme) >0;
	}*/
	/**
	 * 插入敏感信息方案
	 * @param groupScheme
	 * @return
	 */
	@Override
	public boolean insertmg(GroupScheme groupScheme) {
		return groupSchemeMapper.insertmg(groupScheme) > 0;
	}

	@Override
	public boolean delGroupScheme(Integer groupId) {

		if (groupId != 0 || !groupId.equals("")) {
			groupSchemeMapper.delGroupScheme(groupId);
			return true;
		}
		return false;
	}

	@Override
	public List<GroupScheme> selectBySchemeAll(PageView pageView,Integer groupId,String ifmName,String ifmNote) {
		Map<String,Object> map = new HashMap<String, Object>(); 
		map.put("paging", pageView);
		map.put("groupId", groupId);
		map.put("ifmName", ifmName);
		map.put("ifmNote", ifmNote);
		List<GroupScheme> list = groupSchemeMapper.selectAll(map);
		return list;
	}
	
	@Override
	public List<GroupScheme> selectfidName(Integer ifmId) {
		return groupSchemeMapper.selectfidName(ifmId);
	}
	
	//删除方案接口
	@Override
	public boolean delGroupSchemeifmId(Integer ifmId) {
		return groupSchemeMapper.delGroupSchemeifmId(ifmId)>0;
	}
	/**
	 * 查询是否存在方案id
	 *
	*/
	public boolean selectByIfmId(Integer ifmId){	
		return groupSchemeMapper.selectByIfmId(ifmId)>0;
	}
	
	//单个查询接口
	@Override
	public List<GroupScheme> selectifmId(Integer ifmId) {
		return groupSchemeMapper.selectifmId(ifmId);
	}
	@Override
	public List<GroupScheme> selectgroupid(Integer groupId){
		return groupSchemeMapper.selectgroupid(groupId);
	};
	/**
	 * 查询组织可拥有栏目数
	 */
	@Override
	public int selectiform(List<Integer> list, Integer groupId) {
		//String[] schemeId = list.toArray(new String[list.size()]);
		int size = list.size();
		Map<String,Object> map = new HashMap<String, Object>();
		if(groupId!=null){
			map.put("schemeId", size);
			map.put("groupId", groupId);
		}
		return groupSchemeMapper.selectiform(map);
	}
	/**
	 * 删除方案组织关系
	 * @param ifmId
	 * @param groupId
	 * @return
	 */
	@Override
	public boolean delgroupIdifmId(Integer ifmId, Integer groupId) {
		return groupSchemeMapper.delgroupIdifmId(ifmId, groupId)>0;
	}
	//查询组织当前拥有方案数
	@Override
	public int selectByGroupId(Integer groupId) {
		return groupSchemeMapper.selectByGroupId(groupId);
	}
}
